//第一层
var express = require('express');
var router = express.Router();
const mongoose = require('mongoose');
var router = express.Router();


const { get2 , Add2 , Put2 , Del2 , getApplicationShop , agreeAndRefuse} = require('../service/shopService')
//获取店铺
router.get('/getAll', async function (req, res, next) {
    const data = await get2();
    res.send(data)
})
// 获取申请商店
router.get("/getApplicationShop" , async function(req,res,next){
    var data = req.query;
    res.send(await getApplicationShop(data))
});
// 同意或拒绝
router.post("/agreeAndRefuse", async function(req,res,next){
    var data = req.body;
    res.send(await agreeAndRefuse(data))
})
//新增店铺
router.post('/Add', async function (req, res, next) {
    const data = await Add2(req.body);
    res.send(data)
})

//修改店铺
router.post('/Put', async function (req, res, next) {
    const data = await Put2(req.body);
    res.send(data)
})

// 自动删除店铺
router.post('/Del', async function (req, res, next) {
    const data = await Del2(req.body);
    res.send(data)
})

// 获取商家个人渲染店铺
router.get('/getAll2', async function (req, res, next) {
    // console.log(req.query._id)
    const data = await mongoose.model('merchantModel').find({_id:req.query._id}).populate('shopId');
    res.send(data)
})
module.exports = router;